﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class GameData
    {
        public string GameToolName { get; set; }
        public string GameItemName { get; set; }
        public Dictionary<string, object> PropertyDictionary { get { return (propertyDictionary == null) ? propertyDictionary = new Dictionary<string, object>() : propertyDictionary; } }

        private Dictionary<string, object> propertyDictionary;

        public GameData Clone()
        {
            GameData gameData = new GameData();
            gameData.GameItemName = this.GameItemName;
            gameData.GameToolName = this.GameToolName;

            foreach (var item in PropertyDictionary)
                gameData.AddData(item.Key, item.Value);

            return gameData;
        }

        public void UpdateGameData(GameItem gameItem)
        {
            if (!string.IsNullOrEmpty(this.GameItemName))
                gameItem = GameItemManager.Instance[this.GameItemName];

            GameToolBase gameToolBase = gameItem.ObtainTool(this.GameToolName);

            foreach (KeyValuePair<string, object> property in PropertyDictionary)
                gameToolBase.UpdateProperty(property.Key, property.Value);
        }

        public void UpdateProperty(GameItem gameItem, string propertyName)
        {
            if (!string.IsNullOrEmpty(this.GameItemName))
                gameItem = GameItemManager.Instance[this.GameItemName];

            GameToolBase gameToolBase = gameItem.ObtainTool(this.GameToolName);

            gameToolBase.UpdateProperty(propertyName, PropertyDictionary[propertyName]);
        }

        public void AddData(string propertyName, object propertyValue)
        {
            PropertyDictionary.Add(propertyName, propertyValue);
        }

        public void RemoveData(string propertyName)
        {
            PropertyDictionary.Remove(propertyName);
        }
    }
}
